//
//  ZKAppInfo.swift
//  ZKNASProj
//
//  Created by 董建伟 on 2022/10/21.
//

import Foundation
import UIKit

/// 屏幕宽度
public let ZKScreenWidth = UIScreen.main.bounds.size.width
/// 屏幕高度
public let ZKScreenHeight = UIScreen.main.bounds.size.height

public var zkstatusBarHeight: CGFloat {
    guard ZKAppInfo.constStatusBarHeight == 0 else {
        return ZKAppInfo.constStatusBarHeight
    }
    if #available(iOS 13.0, *) {
        let statusBarManager = UIApplication.shared.windows.first?.windowScene?.statusBarManager
        let statusHeight =  CGFloat(statusBarManager?.statusBarFrame.size.height ?? 0)
        ZKAppInfo.constStatusBarHeight =  statusHeight
        return statusHeight
    } else {
        // Fallback on earlier versions
    }
    
    
    return 0
}

@objcMembers
public class ZKAppInfo: NSObject {
    
    public class var scale: CGFloat {
        get{
            return 1 / UIScreen.main.scale
        }
    }
    
    /// 底部安全区域
    public class var bottomSafeHeight: CGFloat {
        get{
            if #available(iOS 11.0, *) {
                return UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
            } else {
                return 0
            }
        }
    }
    
    /// 顶部安全区域
    public class var topSafeHeight: CGFloat {
        get{
            if #available(iOS 11.0, *) {
                return zkstatusBarHeight + 44
            } else {
                return 64
            }
        }
    }
    
    /// 状态栏高度
    static var statusBarHeight: CGFloat {
        return zkstatusBarHeight
    }
    
    static var constStatusBarHeight: CGFloat = 0

}
